import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JPanel;


public class Windows extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public static final int WIDTH = GameControler.TILES_SIZE*GameControler.NUMBER_OF_TILES_WIDTH;
	public static final int HEIGHT = GameControler.TILES_SIZE*GameControler.NUMBER_OF_TILES_HEIGHT;
	public static double position_bg;

	private GameView gameView;
	private MenuView menuView;
	private JPanel   currentView;

	private GameControler gameControler;
	private SoundControler soundControler;

	public Windows(GameControler gameControler, SoundControler soundControler) {
		this.gameControler = gameControler;
		this.soundControler = soundControler;
		this.setTitle("AngryUTBM");
		this.setSize(WIDTH, HEIGHT);
		this.loadNewMenu();
		this.addKeyListener(gameControler);
		this.setFocusable(true);
		this.setVisible(true);
		this.setResizable(false);
		this.setMinimumSize(new Dimension(WIDTH, HEIGHT));
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	public void loadNewMenu(){
		if(this.menuView == null)
			this.menuView = new MenuView(gameControler,soundControler);
		this.menuView.switchToMenu(0);
		this.currentView = menuView;
		this.setContentPane(currentView);
		this.validate();
		this.repaint();
	}

	public void loadLevelMenu(int levelMax, int difficulty, int[] scoresLevel) {
		this.menuView.loadLevelMenu(levelMax,difficulty,scoresLevel);
		this.currentView = menuView;
		this.setContentPane(currentView);
		this.validate();
		this.repaint();
	}

	public void loadNewGame(Player player, Map map) {
		this.gameView = new GameView(player, map);
		this.currentView = this.gameView;
		this.setContentPane(this.currentView);
		this.validate();
		this.requestFocus();
	}

	public void loadCurrentGame() {
		this.currentView = gameView;
		this.setContentPane(currentView);
		this.validate();
	}

	public void repaint() {
		this.currentView.repaint();
	}

	public void exitGame() {
		this.soundControler.setOutputVolume(0);
		System.exit(NORMAL);
	}

	public void setPrintScore(int i, int j, int pointsByTargetKilled, int combo_) {
		if(currentView == gameView)
			gameView.setPrintScore(i, j, pointsByTargetKilled, combo_);
	}
}
